package cn.itcast.nems.common.bean;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * 2个元素的元组
 *
 * @author liyong
 * create: 2023-11-29 11:05:58
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class LocalDateTimeRange {
    private LocalDateTime start;
    private LocalDateTime end;

    /**
     * 判断时间范围是否有重叠
     *
     * @param range 时间范围
     * @return 是否有重叠
     */
    public boolean overlap(LocalDateTimeRange range) {
        boolean result = false;
        if (this.start.isBefore(range.start) && this.end.isAfter(range.start)) {
            result = true;
        }
        if (this.start.isBefore(range.end) && this.end.isAfter(range.end)) {
            result = true;
        }
        return result;
    }

    /**
     * 判断时间范围是否包含给定的时间
     *
     * @param localDateTime 给定时间
     * @return 是否包含
     */
    public boolean contains(LocalDateTime localDateTime) {
        return (this.start.isBefore(localDateTime) && this.end.isAfter(localDateTime));
    }
}
